layui.use(['form', 'layer'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

    form.on("submit(add)", function (data) {
        var index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
        //弹出loading
        var url = ctx + "/seek/save";
        $.post(url,data.field,function (result){
            //判断
            if(result.code==200){
                setTimeout(function () {
                    top.layer.close(index);
                    top.layer.msg("操作成功了！");
                    layer.closeAll("iframe");
                    parent.location.reload();
                },500)
                layer.msg("添加成功");
                //刷新
                window.parent.location.reload();
            } else{
                //提示一下
                layer.msg(result.msg,{icon:5 });
            }
        },"json");
        //取消默认跳转行为
        return false;
    });


    /*取消*/
    $("#closeBtn").click(function () {
        //假设这是iframe页
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    });


});